package com.example.transaction_service_b.common;

import com.example.transaction_service_b.service.EventProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/18.
 */
@Component
public class Scheduler {
    @Autowired
    private EventProcessService eventProcessService;

    @Scheduled(cron = "0/5 * * * * ?") //每5秒执行一次
    public void eventProcessDo(){
        List<Map<String,Object>> dataList = eventProcessService.selectDataByNew();
        System.out.println("侦听到MQ事务数据=======》"+dataList);
        if (dataList != null && !dataList.isEmpty()) {
            int rv = eventProcessService.updateDataByStatus();
            if (rv > 0) {
                System.out.println("待处理事务成功全部完成。。。");
            } else {
                System.out.println("待处理事务完成失败。。。");
            }
        } else {
            System.out.println("没有需要处理的事务数据");
        }
    }
}
